package com.example.spider.cluster.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.shoulder.autoconfigure.condition.ConditionalOnCluster;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliOssConfig {

    @Bean
    @ConditionalOnCluster
    @ConditionalOnProperty("oss.enable")
    public OssDownloader ossDownloader(@Value("${oss.ali.endpoint}") String endpoint,
                                       @Value("${oss.ali.accessKeyId}") String accessKeyId,
                                       @Value("${oss.ali.accessKeySecret}") String accessKeySecret,
                                       @Value("${oss.ali.bucketName}") String bucketName) {
        OSS oss = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        return new OssDownloader(oss, bucketName);
    }

}